
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[],
    formData:{
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: '',
    showPrivacy: false
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })
    
    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
    if(options.zh === 'wx.requirePrivacyAuthorize' || options.zh === 'wx.onNeedPrivacyAuthorization') {
      wx.onNeedPrivacyAuthorization(resolve => {
        // 需要用户同意隐私授权时
        // 弹出开发者自定义的隐私授权弹窗
        this.setData({
          showPrivacy: true
        })
        this.resolvePrivacyAuthorization = resolve
      })
      wx.getUserProfile({
        success: console.log,
        fail: console.error
      })
    }
    if(options.zh === 'wx.requirePrivacyAuthorize') {
      wx.requirePrivacyAuthorize({
        success: (res) => {
          this.setData({
            result: res
          })
          // 用户同意授权
          // 继续小程序逻辑
        },
        fail: (res) => {
          this.setData({
            result: res
          })
        }, // 用户拒绝授权
        complete: () => {}
      })
    }
  },
  handleAgreePrivacyAuthorization() {
    // 用户点击同意按钮后
    this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' })
  },
  getFormData(e) {
    console.log('formdata==', e.detail.formData);
    this.setData({
      formData: e.detail.formData
    })
  },
  openPrivacyContract(e) {
    wx.openPrivacyContract({
      success: (res) => {
        this.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }, // 打开成功
      fail: (res) => {
        this.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }, // 打开失败
    })
  },
  getPrivacySetting(e) {
    wx.getPrivacySetting({
      success: (res) => {
        this.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }, // 打开成功
      fail: (res) => {
        this.setData({
          result: res,
          apiName: e.currentTarget.dataset.apiname
        })
      }, // 打开失败
    })
  },
  getUserProfile() {
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log('res', res);
      }
    })
  },
  getPhoneNumberHandle(e) {
    console.log(e, '======getPhoneNumberHandle');
  },
  onUnload() {
  }
})